<template>
	<div class="exportExcel">
		<h1>ExportFile</h1>
	</div>
</template>

<script lang="ts" setup>
import { ref, onMounted, reactive } from "vue";
import { exportExcel, exportZip } from "@/util/exportFile";
import { goods } from "@/api";

let tableData = ref<any>([]);

let loading = ref(false);

let paging = reactive({
	page: 1,
	size: 10,
	total: 0,
});

function pageChange(e: number) {
	paging.page = e;
	getData();
}
function sizeChange(e: number) {
	paging.size = e;
	getData();
}

let exportFileName = ref("");

function exportTable(type: number) {
	// warningMsgBox(`确定导出${type === 0 ? "Excel" : "Zip"}吗？`)
	//     .then(() => {

	//     })
	//     .catch(() => {});
	const header = ["id", "title", "price", "mack", "supplier", "img_url"];
	const filterVal = ["_id", "title", "price", "mack", "supplier", "img_url"];
	if (type === 0) {
		exportExcel({
			header,
			data: tableData.value,
			filterVal,
			filename: exportFileName.value,
		});
	} else if (type === 1) {
		exportZip({
			header,
			filterVal,
			data: tableData.value,
			filename: exportFileName.value,
		});
	}
}

async function getData() {
	loading.value = true;
	const {
		data: { list, total },
	} = await goods.queryGoods({
		page: paging.page,
		size: paging.size,
	});
	tableData.value = list;
	paging.total = total;
	loading.value = false;
}

onMounted(() => {
	// getData();
});
</script>
